package com.module.admin.app.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.module.admin.app.dao.AppApiTestLogDao;
import com.module.admin.app.pojo.AppApiTestLog;
import com.module.admin.app.service.AppApiTestDtlService;
import com.module.admin.app.service.AppApiTestLogService;
import com.system.comm.model.Page;
import com.system.comm.utils.FrameNoUtil;
import com.system.handle.model.ResponseFrame;

/**
 * app_api_test_log的Service
 * @author admin
 * @date 2020-12-28 16:11:31
 * @version V1.0.0
 */
@Component
public class AppApiTestLogServiceImpl implements AppApiTestLogService {

	@Autowired
	private AppApiTestLogDao appApiTestLogDao;
	@Autowired
	private AppApiTestDtlService appApiTestDtlService;

	/**
	 * 保存或修改
	 * @param appApiTestLog
	 * @return
	 */
	@Override
	public ResponseFrame save(AppApiTestLog appApiTestLog) {
		ResponseFrame frame = new ResponseFrame();
		appApiTestLog.setAatlId(FrameNoUtil.uuid());
		appApiTestLogDao.save(appApiTestLog);
		appApiTestDtlService.updateStatus(appApiTestLog.getAatdId(), appApiTestLog.getStatus(), appApiTestLog.getAatlId());
		frame.setSucc();
		return frame;
	}

	/**
	 * 根据aatlId获取对象
	 * @param aatlId
	 * @return
	 */
	@Override
	public AppApiTestLog get(String aatlId) {
		return handleDtl(appApiTestLogDao.get(aatlId));
	}

	/**
	 * 分页获取对象
	 * @param appApiTestLog
	 * @return
	 */
	@Override
	public Page<AppApiTestLog> pageQuery(AppApiTestLog appApiTestLog) {
		appApiTestLog.setDefPageSize();
		int total = appApiTestLogDao.findAppApiTestLogCount(appApiTestLog);
		List<AppApiTestLog> data = null;
		if(total > 0) {
			data = appApiTestLogDao.findAppApiTestLog(appApiTestLog);
			for (AppApiTestLog item : data) {
				handleDtl(item);
			}
		}
		Page<AppApiTestLog> page = new Page<AppApiTestLog>(appApiTestLog.getPage(), appApiTestLog.getSize(), total, data);
		return page;
	}
	/**
	 * 处理字典等详细信息的方法
	 * @param appApiTestLog
	 */
	private AppApiTestLog handleDtl(AppApiTestLog appApiTestLog) {
		if (appApiTestLog != null) {
		}
		return appApiTestLog;
	}

	/**
	 * 根据aatlId删除对象
	 * @param aatlId
	 * @return
	 */
	@Override
	public ResponseFrame delete(String aatlId) {
		ResponseFrame frame = new ResponseFrame();
		appApiTestLogDao.delete(aatlId);
		frame.setSucc();
		return frame;
	}

	@Override
	public AppApiTestLog getLast(String aatdId) {
		return appApiTestLogDao.getLast(aatdId);
	}

	@Override
	public ResponseFrame update(AppApiTestLog appApiTestLog) {
		ResponseFrame frame = new ResponseFrame();
		if (appApiTestLog.getStatus() == 30) {
			appApiTestLog.setStatusMsg("人工审阅设置通过");
			appApiTestLog.setResultComparison("");
		} else if (appApiTestLog.getStatus() == 40) {
			appApiTestLog.setStatusMsg("不通过");
			appApiTestLog.setResultComparison("人工审阅设置不通过");
		}
		appApiTestLogDao.update(appApiTestLog);
		AppApiTestLog obj = get(appApiTestLog.getAatlId());
		appApiTestDtlService.updateStatus(obj.getAatdId(), appApiTestLog.getStatus(), appApiTestLog.getAatlId());
		frame.setSucc();
		return frame;
	}

	@Override
	public List<AppApiTestLog> findByAatId(String aatId) {
		return appApiTestLogDao.findByAatId(aatId);
	}

	@Override
	public List<String> findBatchNoByAatId(String aatId) {
		return appApiTestLogDao.findBatchNoByAatId(aatId);
	}

	@Override
	public List<AppApiTestLog> findByAatIdBatchNo(String aatId, String batchNo) {
		return appApiTestLogDao.findByAatIdBatchNo(aatId, batchNo);
	}

	@Override
	public AppApiTestLog getByAatIdOrderby(String aatId, String orderby) {
		return appApiTestLogDao.getByAatIdOrderby(aatId, orderby);
	}
}